import re
# 配置------------------------------------------------------------------------------------------------

f = open("../config.txt",encoding='utf-8')
config = f.read()
f.close()
  
replaceArr = [
    "outputName='[\w]+'",
    "tableName='[\w]+'",
    "keyName='[\w]+'",
    "dJudgeNum='[\w]+'"
]

configArr = [0]*4  
for index, item in enumerate(replaceArr):
    first = re.findall(item, config)[0]
    second = re.findall("'[\w]+'",first)[0]
    configArr[index] = re.findall("[\w]+",second)[0]

# for i in configArr:
#     print(i)
# import sys
# sys.exit(0)

outputName = configArr[0]
tableName=configArr[1]
keyName = configArr[2]
dJudgeNum = configArr[3]





#生成文件------------------------------------------------------------------------------------------
file1 = open("../pb/m_tmp.srm", encoding='utf-16')
file2 = open("../pb/pw_tmp.srw", encoding='utf-16')
file3 = open("../pb/w_tmp.srw", encoding='utf-16')
file = [file1,file2,file3]

findArr = ["d_tmp_query","d_tmp_pw","d_tmp","m_tmp","pw_tmp","w_tmp","pt_mstr","pt_part","dJudgeNum"]
str = [
    "d_"+outputName+"_query",
    "d_"+outputName+"_pw",
    "d_"+outputName,
    'm_' + outputName,
    'pw_' + outputName,
    'w_' + outputName,
    tableName,
    keyName,
    dJudgeNum
]
type = ['.srm','.srw','.srw']


for index, item in enumerate(file):
    text = item.read()

    for index2, item2 in enumerate(findArr):
        text = re.compile(item2).sub(str[index2], text)

    f = open("../output/"+str[index+3]+type[index],"w",encoding='utf-16')
    f.write(text)
    f.close()       
    item.close()




  
